use crate::gen_title;

pub fn ch2_4_1() {
    gen_title("ch2_4_1", 18);

    let y = {
        let x = 3;
        x + 1
    };

    println!("The value of y is: {}", y);
}

pub fn ch2_4_2() {
    gen_title("ch2_4_2", 18);

    assert_eq!(ret_unit_type(), ());
}

fn ret_unit_type() {
    let x = 1;

    let y = if x % 2 == 1 { "odd" } else { "even" };

    let z = if x % 2 == 1 { "odd" } else { "even" };

    println!("x = {}, y = {}, z = {}", x, y, z);
}

pub fn ch2_4_pra_1() {
    gen_title("ch2_4_pra_1", 18);

    let x = 5u32;

    let y = {
        let x_squared = x * x;
        let x_cube = x_squared * x;

        x_cube + x_squared + x
    };

    let z = {
        2 * x;
    };

    println!("x is {:?}", x);
    println!("y is {:?}", y);
    println!("z is {:?}", z);
}

pub fn ch2_4_pra_2() {
    gen_title("ch2_4_pra_2", 18);

    let v = {
        let mut x = 1;
        x += 2;
        x
    };

    assert_eq!(v, 3);

    println!("v = {}", v);
}

pub fn ch2_4_pra_3() {
    gen_title("ch2_4_pra_3", 18);

    let v = {
        let x = 3;
        x
    };

    assert_eq!(v, 3);
    println!("v = {}", v);
}

pub fn ch2_4_pra_4() {
    gen_title("ch2_4_pra_4", 18);

    let s = sum(1, 2);
    assert_eq!(s, 3);
    println!("s = {}", s);
}

fn sum(x: i32, y: i32) -> i32 {
    x + y
}
